import { getDB } from "../utils/db/mysql";
export default defineEventHandler(async (event) => {
  // console.log("事件", event);
  let con = getDB();
  let body = await readBody(event)
  console.log(body, 'login');
  let { username, password } = body
  let [data] = await con.query("select * from userinfo where username = ? and password = ?", [username, password]);
  if (data.length >= 1) {
    setCookie(event, "token", "123456", {
      maxAge: 60 * 60 * 24 * 7, // 一周
    });
    //  查询数据库 判断有没有该用户
    //  设置cookie
    return {
      code: 2000,
    }
  } else {
    return {
      code: 4001
    }
  }


});
